home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / precisionPrompt.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.7 KB  |  84 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. //  Procedure Name:
  19. //        precisionPrompt
  20. //
  21. //  Description Name;
  22. //        Displays a modal dialog to get a decimal precision value
  23. //        from the user.
  24. //
  25. //  Input Value:
  26. //        $parent - the window to parent the dialog to (empty if none)
  27. //        $oldPrecision - the current value
  28. //        $max - highest allowable value
  29. //
  30. //  Output Value:
  31. //        0 = if user cancelled
  32. //        > 0 - the new precision
  33. // 
  34.  
  35. global proc int precisionPrompt (string $parent, int $oldPrecision, int $max) 
  36. {
  37.     string $returnValue;
  38.     string $precisionStr;
  39.     int $newPrecision = 0;
  40.  
  41.     // Loop until an acceptable integer is entered into the 
  42.     // modal prompt dialog (won't accept text garbage)
  43.  
  44.     for (;;) {
  45.  
  46.         if ($parent == "") {
  47.             $returnValue = `promptDialog -title "Change Precision" 
  48.                         -message "Enter Number of Decimal Places:" 
  49.                         -text $oldPrecision -button "OK" 
  50.                         -button "Cancel" -db "OK"`;
  51.         } else {
  52.             $returnValue = `promptDialog -title "Change Precision" 
  53.                         -message "Enter Number of Decimal Places:" 
  54.                         -text $oldPrecision -button "OK" 
  55.                         -button "Cancel" -db "OK"
  56.                         -parent $parent`;
  57.         }
  58.                 
  59.         if ($returnValue != "OK")
  60.             break;
  61.  
  62.         $precisionStr = `promptDialog -q`;
  63.         $newPrecision = (int) $precisionStr;
  64.  
  65.         // Determine if the number entered is within a reasonable bound
  66.  
  67.         int $isWithinBounds = $newPrecision >= 1 && $newPrecision <= $max;
  68.  
  69.         // Convert the string to an integer and back, and if the string 
  70.         // is still the same then the string entered must have been a 
  71.         // proper integer. Also, this way float values aren't accepted!
  72.  
  73.         if ($precisionStr == (string) $newPrecision && $isWithinBounds) {
  74.             break;
  75.         } else {
  76.             catch( error( "\"" + $precisionStr + 
  77.                 "\" is not valid, please enter an integer between 1 and " + 
  78.                 $max + "." ) );
  79.         }
  80.     }
  81.  
  82.     return $newPrecision;
  83. }
  84.